<!--论文隐匿名评审查询-->
<template>
    <div class="con">
        <inner-breadcrumb v-model="pathKey" :path="path"></inner-breadcrumb>
        <div v-show="pathKey==='main'">
            <ConditionCard shadow="never" body-style="padding: 24px 24px 6px 24px;" @search="onSubmit" @reset="reset('queryForm')">
                <el-form ref="queryForm" label-suffix="：" :model="queryForm" label-position="right" label-width="120px">
                    <el-row :gutter="24">
                        <!-- <el-col :span="8">
                            <el-form-item :label="$t('label.schoolTerm')">
                                <CalendarSelect v-model="queryForm.yearTerm" @load-done="loadDone"></CalendarSelect>
                            </el-form-item>
                        </el-col> -->
                        <el-col :span="8">
                            <el-form-item :label="$t('label.grade')">
                                <el-date-picker v-model="queryForm.grade" value-format="yyyy" :clearable="true" type="year" :placeholder="$t('paperBlindTrial.gredeTips')" style="width: 100%" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.college')">
                              <el-select
                                v-model="queryForm.academyCode"
                                style="width: 100%;"
                                clearable
                                filterable
                                :placeholder="$t('common.text.all')"
                                v-clearreadonly
                              >
                                <el-option
                                    v-for="item in options.academyCode"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                              </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('courseSummary.major')">
                                <MyMajor :faculty="queryForm.academyCode" :filterable="true" :grade="queryForm.grade" v-model="queryForm.majorCode" :clearable="true" v-clearreadonly> </MyMajor>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingLevel')" prop="eduLevel">
                                <DictSelect v-model="queryForm.eduLevel" :data="options.eduLevel" :clearable="true" ></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingCategory')" prop="eduMode">
                                <DictSelect v-model="queryForm.eduMode" :filterable="true" :data="options.eduMode" :clearable="true" ></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.degreeCategory')" prop="degreeType">
                                <DictSelect v-model="queryForm.degreeType" :data="options.degreeType" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.formLearning')" prop="studyForm">
                                <DictSelect v-model="queryForm.studyForm" :data="options.studyForm" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.preDefenseFlag')">
                                <DictSelect
                                    v-model="queryForm.preDefenseFlag"
                                    :data="options.preDefenseFlag"
                                    :clearable="true"
                                ></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item :label="$t('paperBlindTrial.isDraw')">
                            <DictSelect v-model="queryForm.selectedFlag" :data="options.selectedFlag" :clearable="true"></DictSelect>
                          </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                          <el-form-item :label="$t('paperBlindTrial.createBlindTime')">
                            <el-date-picker
                              style="width: 100%;"
                              v-model="queryForm.selectDate"
                              type="datetimerange"
                              value-format="timestamp"
                              range-separator="~"
                              :default-time="['00:00:00', '23:59:59']"
                              :start-placeholder="$t('message.startDate')"
                              :end-placeholder="$t('message.endDate')">
                            </el-date-picker>
                          </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.sendCount')">
                              <DictSelect v-model="queryForm.evaCount" :data="options.passCount" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item :label="$t('paperBlindTrial.havSendArticles')">
                            <DictSelect v-model="queryForm.evaThesisCount" :data="options.passCount" :clearable="true"></DictSelect>
                          </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.needPassNum')">
                              <DictSelect v-model="queryForm.needPassCount" :data="options.passCount" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item :label="$t('paperBlindTrial.hasPassNum')">
                            <DictSelect v-model="queryForm.passThesisCount" :data="options.passCount" :clearable="true"></DictSelect>
                          </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.finallyResult')">
                                <DictSelect v-model="queryForm.finalResult" :data="options.resultType" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                      <el-col :span="8">
                        <el-form-item :label="$t('paperBlindTrial.manageDept')">
                          <DictSelect v-model="queryForm.manageDeptId" :data="options.manageDeptIds" :clearable="true"></DictSelect>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item :label="$t('paperBlindTrial.tutor')" v-if="!global.isAnyTeacher">
                          <el-select v-model="queryForm.stuTutorNo" :remote-method="selectTeacher"  :placeholder="$t('paperBlindTrial.teacherNameTips')"
                            filterable remote style="width: 100%;" :clearable="true" v-clearreadonly>
                            <el-option v-for="item in teachers" :key="item.value" :label="item.label" :value="item.value"/>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item :label="$t('paperBlindTrial.dataSource')">
                          <DictSelect v-model="queryForm.dataSource" :data="options.dataSources" :clearable="true"></DictSelect>
                        </el-form-item>
                      </el-col>
                    </el-row>
                </el-form>
            </ConditionCard>
            <el-card shadow="never" body-style="padding: 24px;">
              <h1 class="condition-title">{{$t('paperBlindTrial.reviewViewLabel')}}</h1>
              <div class="edu-opertion-bar">
                  <div class="float-left">
                      <KeywordInput v-model="queryForm.stuNoOrName" :placeholder="$t('achievementApply.tableIplaceholder')" @enter="search"></KeywordInput>
                  </div>
                  <div class="float-right">
                      <el-button type="primary" @click="exportData">{{$t('common.btn.export')}}</el-button>
                      <el-button type="danger" @click="openRecheckingSystem">
                        <span style="font-size: 16px;font-weight: bold">{{$t('paperBlindTrial.recheckingSystem')}}</span>
                      </el-button>
                  </div>
              </div>
              <edu-table ref="tables" :url="tableApi"  @selection-change="handleSelectionChange" :orderFixed="true">
                  <el-table-column :min-width="90" :label="$t('label.stuCode')" prop='stuNo' show-overflow-tooltip fixed="left">
                  </el-table-column>
                  <el-table-column :min-width="70" :label="$t('label.stuName')" prop='stuName' show-overflow-tooltip fixed="left">
                  </el-table-column>
                  <el-table-column :min-width="item.width" v-for="item in labelFirst" :key="item.props" :label="item.label" :prop="item.props" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <span>{{scope.row[item.props]}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column :min-width="90" :label="$t('paperBlindTrial.preDefenseFlag')" prop="preDefenseFlag" show-overflow-tooltip
                  :formatter="(row) => { return fieldChange(options.preDefenseFlag, row.preDefenseFlag); }">
                  </el-table-column>
                  <el-table-column :min-width="item.width" v-for="item in labelSecond" :key="item.props" :label="item.label" :prop="item.props" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <span v-if="item.props == 'selectedFlag'">{{fieldChange(options.selectedFlag, scope.row[item.props])}}</span>
                      <span v-else>{{scope.row[item.props]}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column :min-width="80" :label="$t('paperBlindTrial.dataSource')" prop="dataSource" show-overflow-tooltip
                  :formatter="(row) => { return fieldChange(options.dataSources, row.dataSource); }">
                  </el-table-column>
                  <el-table-column :min-width="80" :label="$t('paperBlindTrial.finallyResult')" prop="finalResult" show-overflow-tooltip
                  :formatter="(row) => { return fieldChange(options.resultType, row.finalResult); }" fixed="right">
                  </el-table-column>
                  <el-table-column width="80px" :label="$t('nonPublicCourseOpen.operation')" fixed="right">
                      <template slot-scope="scope">
                          <div class="con_btns">
                              <el-button type="text" @click="showDetail('detailPage', scope.row)">{{$t('message.Look')}}</el-button>
                          </div>
                      </template>
                  </el-table-column>
              </edu-table>
            </el-card>
        </div>
        <!-- 评审详情页面 -->
        <detailPage v-if="pathKey==='detailPage'" :row="objs" @emit:back="backFunc"></detailPage>
    </div>
</template>

<script>
import { queryGradeList, gradeExport } from "common/src/api/paperBlindTrial";
import MyMajor from "common/src/views/administrator/undergraduateTutor/component/MyMajor";
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import detailPage from './detailPage';
import { findTeacherInfoList } from 'common/src/api/studentinfo';
import mixin from 'common/src/mixins/index';
export default {
    components: {
      MyMajor,
      detailPage
    },
    mixins: [commonMixins,mixin],
    props: {},
    data() {
        return {
            tableApi: queryGradeList,
            rows: {},
            teachers: [], // 导师信息
            yearTerms: '',
            queryForm: {
                manageDeptId:'',
                stuNoOrName: '',
                grade: '',
                academyCode: '',
                majorCode: '',
                eduLevel: '',
                eduMode: '',
                degreeType: '',
                studyForm: '',
                preDefenseFlag: '',
                selectedFlag: '',
                evaCount: '',
                evaThesisCount: '',
                needPassCount: '',
                passThesisCount: '',
                finalResult: '',
                selectDate: [], // 抽盲时间
                stuTutorNo:'',
                dataSource:''//数据来源
            },
            labelFirst: [
                { label: this.$t('paperBlindTrial.manageDept'), props: 'manageDeptIdI18n', width: 120 },
                { label: this.$t('label.grade'), props: 'grade', width: 80 },
                { label: this.$t('label.college'), props: 'academyName', width: 150 },
                { label: this.$t('courseSummary.major'), props: 'majorName', width: 150 },
                { label: this.$t('label.trainingLevel'), props: 'eduLevelI18n', width: 80 },
                { label: this.$t('label.trainingCategory'), props: 'eduModeI18n', width: 100 },
                { label: this.$t('label.degreeCategory'), props: 'degreeTypeI18n', width: 80 },
                { label: this.$t('label.formLearning'), props: 'studyFormI18n', width: 80 },
                { label: this.$t('paperBlindTrial.stuTutorNo'), props: 'stuTutorNo', width: 90 },
                { label: this.$t('paperBlindTrial.stuTutorName'), props: 'stuTutorName', width: 80 },
            ],
            labelSecond: [
                { label: this.$t('paperBlindTrial.isDraw'), props: 'selectedFlag', width: 80 },
                { label: this.$t('paperBlindTrial.createBlindTime'), props: 'selectDate', width: 155 },
                { label: this.$t('paperBlindTrial.sendCount'), props: 'evaCount', width: 90 },
                { label: this.$t('paperBlindTrial.havSendArticles'), props: 'evaThesisCount', width: 90 },
                { label: this.$t('paperBlindTrial.needPassNum'), props: 'needPassCount', width: 90 },
                { label: this.$t('paperBlindTrial.hasPassNum'), props: 'passThesisCount', width: 90 },
            ],
            options: {
              majorCode: [], // 专业
              academyCode: [], // 学院
              eduLevel: [], // 培养层次
              eduMode: [], // 培养类别
              degreeType: [], // 学位类型
              studyForm: [], // 学习形式
              passCount: [],
              preDefenseFlag: [
                { label: this.$t('message.yes'), value: 'Y', type: 'success' },
                { label: this.$t('message.no'), value: 'N', type: 'danger' }
              ],
              selectedFlag: [
                { label: this.$t('paperBlindTrial.notDrawn'), value: 'UNBLIND', type: '' }, // 未抽盲
                { label: this.$t('paperBlindTrial.drawn'), value: 'Y', type: 'success' }, // 抽中
                { label: this.$t('paperBlindTrial.missed'), value: 'N', type: 'warning' } // 未中
              ],
              resultType: [
                { label: this.$t('message.pass'), value: 'COMPLETE', type: 'success' },
                { label: this.$t('message.noPass'), value: 'UNPASS', type: 'danger' },
                // { label: this.$t('paperBlindTrial.finished'), value: 'COMPLETE', type: 'success' },
                { label: this.$t('achievementApply.unfinished'), value: 'INCOMPLETE' },
              ], // 评审结果
              dataSources: [
                { label: this.$t('paperBlindTrial.system'), value: 'system', type: '' }, // 系统数据
                { label: this.$t('paperBlindTrial.import'), value: 'import', type: 'success' }, // 导入数据
                { label: this.$t('paperBlindTrial.sync'), value: 'sync', type: 'warning' } // 同步数据
              ],
              manageDeptIds:[
                { label: this.$t('paperBlindTrial.general'), value: '2', type: '' },
                { label: this.$t('paperBlindTrial.onJob'), value: '4', type: '' }
              ],//管理部门
            },
            dialogFlag: false,
            typeInfo: '',
            selectionDatas: [],
            pathKey: 'main',
            path: {
              label: this.$t('paperBlindTrial.reviewInnerLabel'),
              key: 'main',
              disable: false,
              children: [
                { label: this.$t('paperBlindTrial.reviewDetail'), key: 'detailPage', disable: true, }
              ]
            },
            objs: {}
        };
    },
    computed: {

    },
    created() {

    },
    mounted() {
      let param = {
        X_YX: 'academyCode', // 学院
        X_PYCC: 'eduLevel', // 培养层次
        X_PYLB: 'eduMode', // 培养类别
        X_XWLX: 'degreeType', // 学位类型
        K_XXXS: 'studyForm', // 学习形式
      };
      this.initOptions(param);
      this.onSubmit();
      for (let i = 0; i <= 50; i++) {
        let obj = { label: i, value: i, id: i };
        this.options.passCount.push(obj);
      }
    },
    methods: {
        //打开查重系统
        openRecheckingSystem(){
            window.open("https://lwcc.tongji.edu.cn/lw/user/login");
        },

        //可用TeacherSelect通用组件替换
        selectTeacher(query) {
            if (!query) return
            const data = {
                condition: query,
                pageNum_: 1,
                pageSize_: 10
            }
            this.loading = true
            findTeacherInfoList(data)
                .then(res => {
                    this.loading = false
                    if (res.code == 200) {
                        this.teachers = this.transData(res.data.list, 'name', 'code')
                    } else throw res.code
                })
                .catch(error => {
                    this.loading = false
                    console.error("查询导师信息失败")
                })
        },

        transData(list, name, code) {
            return list.map((item, index, array) => {
                return {
                    label: item[name] + '(' + item[code] + ')',
                    value: item[code],
                }
            })
        },

        exportData() { // 导出
          let jsons = this.$refs.tables.selectionDatas;
          let param = {};
          if (jsons && jsons.length > 0) { // 优先按勾选内容导出
            param.ids = jsons.map(v => v.id);
            param.type = 1;
          } else { // 存在搜索条件时则按搜索条件导出
            //param.request = this.queryForm;
            if(this.queryForm.stuNoOrName ){
                param.request = {stuNoOrName:this.queryForm.stuNoOrName.trim()}
            }else{
                param.request = _.cloneDeep(this.queryForm);
                if (param.request.selectDate && param.request.selectDate.length > 0) {
                    param.request.selectDateBegin = param.request.selectDate[0]; // 开始时间
                    param.request.selectDateEnd = param.request.selectDate[1]; // 结束时间
                }
                delete param.request.selectDate;
                param.request.stuNoOrName = '';
            }
            param.type = 0;
          }
          gradeExport(param);
        },
        onSubmit() { // 筛选
          this.$refs.tables.pageNum = 1;
          let param = {};
          if(this.queryForm.stuNoOrName ){
            param = {stuNoOrName:this.queryForm.stuNoOrName.trim()}
          }else{
            param = _.cloneDeep(this.queryForm);
            if (param.selectDate && param.selectDate.length > 0) {
                param.selectDateBegin = param.selectDate[0]; // 开始时间
                param.selectDateEnd = param.selectDate[1]; // 结束时间
            }
            delete param.selectDate;
            param.stuNoOrName = '';
          }
          this.$refs.tables.search(param);
        },
        reset() {  // 重置
          for (const key in this.queryForm) {
            if (key !== 'yearTerm') {
              this.queryForm[key] = '';
            }
          }
          this.queryForm.selectDate = [];
          this.queryForm.yearTerm = this.yearTerms;
          this.onSubmit();
        },
        search() { // 搜索
          this.queryForm.stuNoOrName = this.queryForm.stuNoOrName.trim();
          this.onSubmit();
        },
        loadDone() { // 页面加载时保存学期学年
            this.yearTerms = this.queryForm.yearTerm;
        },
        // 多选方法
        handleSelectionChange (val) {
          this.selectionDatas = val;
        },
        // 查看评审详情方法
        showDetail (type, row) {
          this.pathKey = type;
          this.objs = row;
        },
        // 评审详情返回方法
        backFunc () {
          this.pathKey = 'main';
          this.onSubmit();
        },
    }
};
</script>

<style scoped lang="scss">
.con {
    &_searchRight {
        margin-left: 10px;
    }
}
.condition-title {
  color: #2b3b4e;
  font-size: 18px;
  line-height: 24px;
  font-weight: bold;
}
</style>

